package com.wn.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.bean.House;
import com.wn.bean.HouseQueryDto;
import com.wn.bean.PageVo;
import com.wn.mapper.HouseMapper;
import com.wn.service.IHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author yellow Docter
 * @date 2024-07-02
 * @desc 蜗牛创想：www.woniuxy.com
 */
@Service
public class HouseServiceImpl implements IHouseService {

    @Autowired
    private HouseMapper houseMapper;

    @Override
    public PageVo getHouseList(int currentPage, int pageSize, HouseQueryDto houseQueryDto) {

        //01 调用分页查询
        PageHelper.startPage(currentPage,pageSize);
        //02 拿到结果
        List<House> houseList = houseMapper.selectAllHouse(houseQueryDto);
        //03 封装pageInfo对象
        PageInfo<House> pageInfo = new PageInfo<>(houseList);

        long total = pageInfo.getTotal();
        List<House> list = pageInfo.getList();

        //04 封装 Pagevo 对象返回
        PageVo pageVo = new PageVo();
        pageVo.setTotal(total);
        pageVo.setData(list);

        return pageVo;

    }

    @Override
    public boolean addHouse(House house) {
        return houseMapper.addHouse(house) > 0;
    }
}
